package com.demo.miya.controller.client;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * seata miya客户端, 提供给miya服务调用
 * @author cyj
 */
@FeignClient(contextId = "seataMiyaClient", name = "service-miya")
@RestController
public interface SeataMiyaClient {

    /**
     * 测试分布式事务异常回滚
     * 调用该接口会跑RuntimeException
     * @param userId 用户id
     */
    @GetMapping("/insertError")
    void insertError(@RequestParam("userId") Long userId);

    @GetMapping("/insert")
    void insert(@RequestParam("userId") Long userId);

    /**
     * 测试TCC事务
     * @param userId 用户id
     * @param sleepTime 睡眠时间
     * @throws InterruptedException 异常
     */
    @GetMapping("/prepare")
    void prepare(@RequestParam("userId") Long userId, @RequestParam("sleepTime") Long sleepTime) throws InterruptedException;
}
